//
//  ItemVC5.m
//  喜马拉雅FM
//
//  Created by dllo on 16/1/22.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#import "ItemVC5.h"
#import "ItemVC5HeadView.h"
#import "DataBaseHandler.h"
#import "MyCollectViewController.h"

#import "SDImageCache.h"


@interface ItemVC5 ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arrForData;


@end

@implementation ItemVC5

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self.navigationController setNavigationBarHidden:YES];

    self.navigationController.title = @"个人中心";
    self.title = @"个人中心";
    [self handleData];
    [self createTableView];
}

- (void)handleData {


}

#pragma mark createTableView
- (void)createTableView {

    self.tableView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
    [self.view addSubview:self.tableView];
    [self.tableView release];
    
    ItemVC5HeadView *headView = [[ItemVC5HeadView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 250)];
    headView.backgroundColor = [UIColor blackColor];
    self.tableView.tableHeaderView = headView;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.separatorColor = [UIColor grayColor];
    

    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"poolForDengLu"];
}
#pragma mark tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"poolForDengLu"];
    if (indexPath.row == 0) {
  
    cell.textLabel.text = @"我的收藏";
    cell.imageView.image = [UIImage imageNamed:@"shixinxingxing"];
 
    }else {

        cell.textLabel.text = @"缓存清理";
        cell.imageView.image = [UIImage imageNamed:@"huancunqingli"];
    }
       return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.row == 0) {
    MyCollectViewController *collect = [[MyCollectViewController alloc]init];
    [self.navigationController pushViewController:collect animated:YES];
    [self.navigationController setNavigationBarHidden:NO];
        
    }else {
        

        // 获取缓存大小
        NSUInteger size = [[SDImageCache sharedImageCache] getSize];
        
        float cacheSize = size / 1024.0 / 1024.0;
        
//        self.string = [NSString stringWithFormat:@"%.2fM",cacheSize];
        
    
        NSString *str = [NSString stringWithFormat:@"缓存大小为%.2fM,确定要清理缓存吗?",cacheSize];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:str preferredStyle:UIAlertControllerStyleAlert];
        
        UIAlertAction *actionSure = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        // 清除缓存.
        [[SDImageCache sharedImageCache] clearDisk];
        }];
        UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
        
        [alert addAction:actionSure];
        [alert addAction:actionCancel];
          [self presentViewController:alert animated:YES completion:nil];
        }
  
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
